<?php
$title = "NJU网上商城 - 商品信息";
$css = "item.css";
include_once 'common/top.php';
include_once '../Class/DB.php';
$db=new DB();
$pid=$_GET['id'];
if(!isset($pid))
{
	$pid=1;
}
$messagePerPage=4;//留言板每页显示数量
$totalPage=ceil($db->get_pid_messageNum($pid)/$messagePerPage); //计算出总页数
$page=$_GET['page']; //获得当前的页面值
if (!isset($page)) {
 $page=1;
} //如果没有值,则赋值1
$startCount=($page-1)*$messagePerPage; //分页开始,根据此方法计算出开始的记录
$messages=$db->get_productId_message($pid,$startCount, $messagePerPage);//获取对商店的评价
$product=$db->get_pid_product($pid);
$product[0]["introduction"]=str_replace("\r\n", "<br/>", $product[0]["introduction"]);
$product[0]["introduction"]=str_replace("\r", "<br/>", $product[0]["introduction"]);
$product[0]["introduction"]=str_replace("\n", "<br>", $product[0]["introduction"]);
$score=$db->get_pid_score($pid);
//$messages=$db->get_pid_message($pid);

?>
<script src="../js/item.js" type="text/javascript"></script>
<div id="product">
	<div id="product_top"></div>
	<div id="product_show">
		<div>
			<div id="image">
				<img alt="商品" src="<?php echo $product[0]["pic_url"];?>">
			</div>
			<div id="about">
				<h4><?php echo $product[0]["p_name"];?></h4>
				<form action="cart.php" method="post">
				<input type="hidden" name="flag" id="id_flag" value="cart"/>
				<input type="hidden" name="item_pid" value="<?php echo $product[0]["pid"];?>"/>
					<table>
						<tr>
							<th>
								<p>市场价格：</p>
							</th>
							<td>
								<p class="no">￥<?php echo $product[0]["ori_price"];?></p>
							</td>
						</tr>
						<tr>
							<th>
								<p>现&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价：</p>
							</th>
							<td>
								<p class="price">￥<?php echo $product[0]["act_price"];?></p>
							</td>
						</tr>
						<tr>
							<th>
								<p>发&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;货：</p>
							</th>
							<td>
								<p>快递：10.00元 &nbsp;&nbsp; EMS：10.00元</p>
							</td>
						</tr>
						<tr>
							<th>
								<p>已&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;售：</p>
							</th>
							<td>
								<p class="sold"><?php echo $db->get_pid_sold($product[0]["pid"]);?></p>
								<p>件</p>
							</td>
						</tr>
						<tr>
							<th>
								<p>评&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价：</p>
							</th>
							<td>
							<?php 
							$num_start=floor($score);
							$left=$score-$num_start;
							for($k=0;$k<$num_start;$k++)
							{
							?>
							<img src="../image/item_start.png">
							<?php 
							}
							if($left<0.5)
							{
							for($k=0;$k<5-$num_start;$k++)
							{
							?>
							<img src="../image/item_start_none.png">
							<?php 
								
							}
							}else//>=0.5
							{
							?>
							<img src="../image/item_start_half.png">
							<?php 
							for($k=0;$k<5-$num_start-1;$k++)
							{
							?>
							<img src="../image/item_start_none.png">
							<?php 	
							}
							}
							?>
								<p><?php echo $score;?></p>
								<p>（已有</p>
								<p class="sold"><?php echo $db->get_pid_messageNum($pid);?></p>
								<p>人进行了评价）</p>
							</td>
						</tr>
						<tr>
							<th>
								<p>积&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;分：</p>
							</th>
							<td>
								<p class="green"><?php echo $product[0]["act_price"]*0.01;?></p>
								<p>分</p>
							</td>
						</tr>
						
						<tr>
							<th colspan="2" class="line">
							</th>
						</tr>
						
						<tr>
							<th>
								<p>数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量：</p>
							</th>
							<td>
								<input id="pCount" type="text" name="number" value="1" onkeyDown="onlyNum();" >
								<p>件</p>
								<p class="gray">(库存 <?php echo $product[0]["count"];?>件)</p>
							</td>
						</tr>
						<tr>
							<th>
							</th>
							<td>
								<input type="submit" value="" onclick="check(<?php echo $product[0]["count"];?>);">
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="clearfix"></div>
		</div>
		
		<div id="introduce" class="block_mode">
			<h3>商品简介</h3>
			<div class="block_context">
				<p><?php echo $product[0]["introduction"];?></p>
			</div>
		</div>
		
		<div id="estimate" class="block_mode">
			<h3>评价详情</h3>
			<?php 
			$i=0;
			while(isset($messages[$i]))
			{
				$user_info=$db->get_uid_info($messages[$i]["uid"]);
			?>
			<div class="block_context">
				<div class="estimate">
					<b> 
					<?php 
					        echo $user_info[0]["userName"];
					        $score=$messages[$i]["score"];
							$num_start=floor($score);
							$left=$score-$num_start;
							for($k=0;$k<$num_start;$k++)
							{
							?>
							<img src="../image/item_start.png">
							<?php 
							}
							if($left<0.5)
							{
							for($k=0;$k<5-$num_start;$k++)
							{
							?>
							<img src="../image/item_start_none.png">
							<?php 
								
							}
							}else//>=0.5
							{
							?>
							<img src="../image/item_start_half.png">
							<?php 
							for($k=0;$k<5-$num_start-1;$k++)
							{
							?>
							<img src="../image/item_start_none.png">
							<?php 	
							}
							}
							echo $messages[$i]["score"];
							?>
					</b>
					<p class="data"><?php echo substr($messages[$i]["date"],0,4)."-".substr($messages[$i]["date"],4,2)."-".substr($messages[$i]["date"],6,2)." ".substr($messages[$i]["date"],8,2).":".substr($messages[$i]["date"],10,2);?></p>
					<p><?php 
					$messages[$i]["content"]=str_replace("\r\n", "<br/>", $messages[$i]["content"]);
					$messages[$i]["content"]=str_replace("\r", "<br/>", $messages[$i]["content"]);
					$messages[$i]["content"]=str_replace("\n", "<br>", $messages[$i]["content"]);
					echo $messages[$i]["content"];
					?>
					</p>
				</div>
			</div>
			<?php 
			$i++;
			}
			?>
		<div id="page">
			<?php if ($page != 1) { //页数不等于1?>
			<a href="item.php?id=<?php echo $pid?>&page=<?php echo $page - 1;?>">上一页</a> <!--显示上一页-->
			<?php }
			for ($i=1;$i<=$totalPage;$i++) {  //循环显示出页面
				if($i==$page){
					?>
					<p><?php echo $i;?></p>
			<?php continue;}
			?>
			<a href="item.php?id=<?php echo $pid?>&page=<?php echo $i;?>"><?php echo $i ;?></a>
			<?php
			}
			if ($page<$totalPage) { //如果page小于总页数,显示下一页链接
			?>
				<a href="item.php?id=<?php echo $pid?>&page=<?php echo $page + 1;?>">下一页</a>
			<?php
					} 
			?>
			
			</div>
		</div>
	</div>
	
	
	<div id="product_end"></div>
</div>

<?php
include_once 'common/tail.php';
?>